﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Runtime.InteropServices;

namespace WFFS
{
    public partial class FrmPower : Form
    {
        private Form1 frmMain = null;
        public FrmPower()
        {
            InitializeComponent();
        }
        public FrmPower(Form1 _frm)
        {
            InitializeComponent();
            frmMain = _frm;
        }

        private void FrmSendMSG_FormClosed(object sender, FormClosedEventArgs e)
        {
            string x = this.Location.X.ToString();
            string y = this.Location.Y.ToString();
            WriteIniData("FrmPower", "X", x, Application.StartupPath + @"\WFFS.ini");
            WriteIniData("FrmPower", "Y", y, Application.StartupPath + @"\WFFS.ini");
        }
        public static bool WriteIniData(string Section, string Key, string Value, string iniFilePath)
        {
            if (File.Exists(iniFilePath))
            {
                long OpStation = WritePrivateProfileString(Section, Key, Value, iniFilePath);
                if (OpStation == 0)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            else
            {
                return false;
            }
        }
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

        private void button1_Click(object sender, EventArgs e)
        {
            string sql2 = "";
            string useduty="";
            string lname="";
            string ltype="";

            if (rb1.Checked)
                useduty = "社会车辆";
            else
                useduty = "社会人员";

            if (txtName.Text == "")
            {
                MessageBox.Show("请输入力量名称!");
                return;
            }
            else
                lname = txtName.Text;

            if (cmbType.Text == "")
            {
                MessageBox.Show("请选择力量类型!");
                return;
            }
            else
                ltype = cmbType.Text;


            sql2 = "insert SocietyPower(Section,LLName,LLType,UseOrDuty,EnterTime,State) VALUES ('','"
                    + lname.Trim() + "','" + ltype.Trim() + "','" + useduty.Trim() + "','" + System.DateTime.Now.ToString()
                    + "','×')";

            SqlDataReader reader2 = null;
            SqlCommand cmd2 = new SqlCommand(sql2, frmMain.dbConnect);
            reader2 = cmd2.ExecuteReader();
            reader2.Close();
            MessageBox.Show("保存成功!");
        }
    }
}
